package com.yitao.cms.service.overseasLogisticsInfo;


import com.skipper.base.service.GenericEntityService;
import com.yitao.cms.dto.overseasLogistics.OverseasProductInfoDto;
import com.yitao.cms.model.overseasLogistics.OverseasProductInfoModel;

import com.yitao.cms.model.overseasLogistics.QOverseasProductInfoModel;
import com.yitao.cms.utils.BaseUtils;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import javax.persistence.EntityManager;
import javax.transaction.Transactional;
import java.io.DataOutput;
import java.util.List;
import java.util.stream.Collectors;


/**
 * @Author: wwl
 * @Date: 2019/4/9 11:59
 * @Description:
 */
@Service
public class OverseasProductInfoService extends GenericEntityService<OverseasProductInfoModel, OverseasProductInfoDto, QOverseasProductInfoModel> {
    public OverseasProductInfoService(EntityManager entityManager) {
        super(entityManager);
    }

    private BaseUtils base = BaseUtils.getInstance();

    @Transactional
    public List<OverseasProductInfoModel> insertProductInfo(List<OverseasProductInfoModel> productInfoModelList){
        if (productInfoModelList!=null && productInfoModelList.size()>0){
           List<OverseasProductInfoModel> list = repository.save(productInfoModelList);
           return list;
        }
        return null;
    }

    /**
     * 根据编号查询信息
     * @param overseaExpressNo
     * @return
     */
    public List<OverseasProductInfoDto> findProductByNo(String overseaExpressNo){
        if (StringUtils.isNotBlank(overseaExpressNo)){
           return repository.findAll(Q.overseaExpressNo.eq(overseaExpressNo).and(Q.isDelete.eq(false))).stream().map(this::convertEntityToDto).collect(Collectors.toList());
        }
        return null;
    }















}
